﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Agility.Office.ExcelAddIn.Properties;

namespace Agility.Office.ExcelAddIn
{
    public partial class AgilitySettingsDialog : Form
    {
        public AgilitySettingsDialog()
        {
            InitializeComponent();
            if (string.IsNullOrEmpty(this.textBoxAgilityUrl.Text))
            {
                errorProviderAgilityUrl.SetError(this.textBoxAgilityUrl, Properties.Resources.LoginErrorLoginDataIncompleteMessage);
            }
            if (string.IsNullOrEmpty(this.textBoxUserName.Text))
            {
                errorProviderUserName.SetError(this.textBoxUserName, Properties.Resources.LoginErrorLoginDataIncompleteMessage);
            }
        }

        public string UserName 
        {
            get { return this.textBoxUserName.Text; }
            private set { }
        }

        public string Password 
        {
            get { return this.textBoxPassword.Text; }
            set { }
        }

        private void buttonOk_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(this.textBoxPassword.Text))
            {
                errorProviderPassword.SetError(this.textBoxPassword, Properties.Resources.LoginErrorLoginDataIncompleteMessage);
            }
            else if (string.IsNullOrEmpty(errorProviderAgilityUrl.GetError(this.textBoxAgilityUrl)) && 
                     string.IsNullOrEmpty(errorProviderUserName.GetError(this.textBoxUserName)))
            {
                Properties.Settings.Default.Save();
                this.Close();
            }
        }

        private void textBoxAgilityUrl_TextChanged(object sender, EventArgs e)
        {
            this.errorProviderAgilityUrl.Clear();
        }

        private void textBoxUserName_TextChanged(object sender, EventArgs e)
        {
            this.errorProviderUserName.Clear();
        }

        private void textBoxPassword_TextChanged(object sender, EventArgs e)
        {
            this.errorProviderPassword.Clear();
        }
    }
}
